package cn.anc.aonicardv.module.ui.my;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.OnClick;
import cn.anc.aonicardv.Configs;
import cn.anc.aonicardv.Constant;
import cn.anc.aonicardv.R;
import cn.anc.aonicardv.R2;
import cn.anc.aonicardv.module.ui.base.BaseActivity;
import cn.anc.aonicardv.util.SpUtils;

/**
 * Created by yangdai on 2017/6/22.
 */

public class HelpActivity extends BaseActivity {

    @BindView(R2.id.tv_title)
    TextView titleTv;
    @BindView(R2.id.wv_help)
    WebView helpWv;
    private String mLanguage;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_help);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initVariable() {
    }

    @Override
    public void setListener() {

    }

    @Override
    public void initData() {
        WebSettings webSettings = helpWv.getSettings();
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(false);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setDisplayZoomControls(false);
        //自适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);
        helpWv.setWebViewClient(webViewClient);
        mLanguage = SpUtils.getString(Constant.SpKeyParam.APP_LANUAGE, Configs.DEFUTL_LANGUAGE);
        if (Configs.DEFUTL_HELP_HTML.contains(mLanguage + ",")) {
            helpWv.loadUrl("file:///android_asset/help_"+mLanguage+".html");
        }else{
            helpWv.loadUrl("file:///android_asset/help_en.html");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        titleTv.setText(R.string.my_help);
    }

    @OnClick(R2.id.tv_back)
    public void back() {
        finish();
    }

    public WebViewClient webViewClient = new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    };

}
